<?php

class TextboxControl extends ValueControl {
	
	private $width = '100%';
	public function WithWidth($value){ $this->width = $value; return $this; }
	
	private $rows = 1;
	public function WithRows($value){ $this->rows = $value; return $this; }
	
	private $readonly = false;
	public function WithReadonly($value){ $this->readonly = $value; return $this; }
	
	private $style = '';
	public function WithStyle($value){ $this->style = $value; return $this; }
	
	private $on_change = null;
	public function WithOnChange($value){ $this->on_change = $value; return $this; }
	
	private $max_characters = null;
	public function WithMaxCharacters($value){ $this->max_characters = $value; return $this; }
	
	private $nowrap = false;
	public function WithNoWrap($value){ $this->nowrap = $value; return $this; }
	
	public function Render(){
		if ($this->mode == UIMode::Edit){
			if ($this->rows == 1){
				echo '<input type="text" id="'.$this->name.'"';
				if (!$this->readonly) {
					echo ' name="'.$this->name.'"';
					echo ' class="formPane"';	
				}
				else {
					echo ' readonly="readonly"';
					echo ' class="formLocked"';	
				}
				echo ' style="width:'.(empty($this->width)?'auto':$this->width).';'.$this->style.'"';
				
				if (!is_null($this->max_characters))
					echo ' maxlength="'.$this->max_characters.'"';

				if (!is_null($this->on_change)){
					echo ' onchange="'.$this->on_change.'"';
					echo ' onkeyup="'.$this->on_change.'"';
				}
				
				echo ' value="'.$this->value.'" />';
			}
			else {
				echo '<textarea id="'.$this->name.'" rows="'.$this->rows.'"';
				echo ' name="'.$this->name.'"';
				if (!$this->readonly) {
					echo ' name="'.$this->name.'"';
					echo ' class="formPane"';	
				}
				else {
					echo ' readonly="readonly"';
					echo ' class="formLocked"';	
				}

				if (!is_null($this->on_change)){
					echo ' onchange="'.$this->on_change.'"';
					echo ' onkeyup="'.$this->on_change.'"';
				}
				
				if ($this->nowrap) 
					echo ' wrap="off"';
					
				echo ' style="width:'.(empty($this->width)?'auto':$this->width).';'.$this->style.'"';
				echo '>'.$this->value.'</textarea>';
				
				
			}
		}
		else {
			echo $this->value;
		}
	}
	
}
	
	
	
?>